{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:18.309443Z",
     "start_time": "2025-01-01T20:44:16.253010Z"
    }
   },
   "source": [
    "import pickle\n",
    "import pandas as pd\n",
    "import json"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:19.878576Z",
     "start_time": "2025-01-01T20:44:19.863578Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def get_data(dataname):\n",
    "    train_data = pd.read_csv(f\"data/{dataname}/{dataname}_train.csv\")\n",
    "    valid_data = pd.read_csv(f\"data/{dataname}/{dataname}_valid.csv\")\n",
    "    #读取训练集与测试集\n",
    "    with open(f\"data/{dataname}/{dataname}_testset.pk\", \"rb\") as f:\n",
    "        test_file = pickle.load(f) \n",
    "    \n",
    "    tv_data = pd.concat([train_data, valid_data], ignore_index=True)\n",
    "    tv_data.sort_values(['user_id', 'start_day', 'start_min'], inplace=True)\n",
    "    if dataname == 'geolife':\n",
    "        tv_data['duration'] = tv_data['duration'].astype(int)\n",
    "    \n",
    "    return tv_data, test_file\n"
   ],
   "id": "7b18de31e5c2bb0e",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:21.577783Z",
     "start_time": "2025-01-01T20:44:21.446786Z"
    }
   },
   "cell_type": "code",
   "source": "tv_data, test_file = get_data('geolife')",
   "id": "b71412997f3337ab",
   "outputs": [],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:22.919933Z",
     "start_time": "2025-01-01T20:44:22.899935Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#将原始的时间数据由分钟时间转化成12小时制的时间\n",
    "def convert_to_12_hour_clock(minutes):\n",
    "    if minutes < 0 or minutes >= 1440:\n",
    "        return \"Invalid input. Minutes should be between 0 and 1439.\"\n",
    "\n",
    "    hours = minutes // 60\n",
    "    minutes %= 60\n",
    "\n",
    "    period = \"AM\"\n",
    "    if hours >= 12:\n",
    "        period = \"PM\"\n",
    "\n",
    "    if hours == 0:\n",
    "        hours = 12\n",
    "    elif hours > 12:\n",
    "        hours -= 12\n",
    "\n",
    "    return f\"{hours:02d}:{minutes:02d} {period}\"\n",
    "\n",
    "#将日期数据返回成星期数\n",
    "def int2dow(int_day):\n",
    "    tmp = {0: 'Monday', 1: 'Tuesday', 2: 'Wednesday',\n",
    "           3: 'Thursday', 4: 'Friday', 5: 'Saturday', 6: 'Sunday'}\n",
    "    return tmp[int_day]"
   ],
   "id": "d8319be19078821b",
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:24.258463Z",
     "start_time": "2025-01-01T20:44:24.245466Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def get_user_data(train_data, uid, num_historical_stay):\n",
    "    user_train = train_data[train_data['user_id']==uid]\n",
    "    user_train = user_train.tail(num_historical_stay)\n",
    "    return user_train\n"
   ],
   "id": "fef27bf413baab5e",
   "outputs": [],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:25.793185Z",
     "start_time": "2025-01-01T20:44:25.772184Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def organise_data(user_train, test_file, uid, num_context_stay=5):\n",
    "    # 将原始数据进行修改，变成适合查询的数据格式\n",
    "    historical_data = []\n",
    "    \n",
    "    #对原始数据的训练数据进行修改，将开始时间、持续时间、日期、经纬度等转化成合适的格式\n",
    "    for _, row in user_train.iterrows():\n",
    "        historical_data.append(\n",
    "            (convert_to_12_hour_clock(int(row['start_min'])),\n",
    "            int2dow(row['weekday']),\n",
    "            int(row['duration']),\n",
    "            row['location_id'])\n",
    "            )\n",
    "\n",
    "    #创建字典形式，包括过往值与预测值\n",
    "    list_user_dict = []\n",
    "    for i_dict in test_file:\n",
    "        i_uid = i_dict['user_X'][0]\n",
    "        if i_uid == uid:\n",
    "            list_user_dict.append(i_dict)\n",
    "\n",
    "    predict_X = []\n",
    "    predict_y = []\n",
    "    for i_dict in list_user_dict:\n",
    "        construct_dict = {} #创建空的字典集合\n",
    "        context = list(zip([convert_to_12_hour_clock(int(item)) for item in i_dict['start_min_X'][-num_context_stay:]], \n",
    "                        [int2dow(i) for i in i_dict['weekday_X'][-num_context_stay:]], \n",
    "                        [int(i) for i in i_dict['dur_X'][-num_context_stay:]], \n",
    "                        i_dict['X'][-num_context_stay:]))  #将list_user_dict中散乱的数据格式转化成符合规定的形式(时间，星期，停留时间，位置)\n",
    "            \n",
    "        \n",
    "        target = (convert_to_12_hour_clock(int(i_dict['start_min_Y'])), int2dow(i_dict['weekday_Y']), None, \"<next_place_id>\")\n",
    "        construct_dict['context_stay'] = context #历史停留位置为context中的内容\n",
    "        construct_dict['target_stay'] = target  #预测停留位置为target的内容\n",
    "        predict_y.append(i_dict['Y'])\n",
    "        predict_X.append(construct_dict)\n",
    "\n",
    "    return historical_data, predict_X, predict_y"
   ],
   "id": "9b7b62a1cf2d1ea1",
   "outputs": [],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:27.571388Z",
     "start_time": "2025-01-01T20:44:27.557387Z"
    }
   },
   "cell_type": "code",
   "source": [
    "user_train = get_user_data(tv_data, 5, 5)\n",
    "\n",
    "historical_data, predict_X, predict_y = organise_data(user_train, test_file, 5, 5)\n",
    "\n",
    "X = predict_X[1]\n",
    "\n"
   ],
   "id": "ce8a1c869e3c00f",
   "outputs": [],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:29.059856Z",
     "start_time": "2025-01-01T20:44:29.044860Z"
    }
   },
   "cell_type": "code",
   "source": "print(len(predict_X))",
   "id": "3c70402d610d0515",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:30.533874Z",
     "start_time": "2025-01-01T20:44:30.522882Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print(predict_X)\n",
    "print(\"------\")\n",
    "print(historical_data)\n",
    "print(\"------\")\n",
    "print(X)"
   ],
   "id": "975791d047ece26c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'context_stay': [('10:56 AM', 'Saturday', 144, 212), ('03:13 AM', 'Sunday', 106, 223), ('07:31 AM', 'Sunday', 280, 1), ('12:16 PM', 'Sunday', 645, 204), ('11:42 PM', 'Sunday', 301, 205)], 'target_stay': ('09:51 AM', 'Monday', None, '<next_place_id>')}, {'context_stay': [('03:13 AM', 'Sunday', 106, 223), ('07:31 AM', 'Sunday', 280, 1), ('12:16 PM', 'Sunday', 645, 204), ('11:42 PM', 'Sunday', 301, 205), ('09:51 AM', 'Monday', 135, 210)], 'target_stay': ('12:20 PM', 'Monday', None, '<next_place_id>')}, {'context_stay': [('07:31 AM', 'Sunday', 280, 1), ('12:16 PM', 'Sunday', 645, 204), ('11:42 PM', 'Sunday', 301, 205), ('09:51 AM', 'Monday', 135, 210), ('12:20 PM', 'Monday', 646, 204)], 'target_stay': ('12:33 PM', 'Wednesday', None, '<next_place_id>')}, {'context_stay': [('12:16 PM', 'Sunday', 645, 204), ('11:42 PM', 'Sunday', 301, 205), ('09:51 AM', 'Monday', 135, 210), ('12:20 PM', 'Monday', 646, 204), ('12:33 PM', 'Wednesday', 630, 204)], 'target_stay': ('03:17 AM', 'Thursday', None, '<next_place_id>')}, {'context_stay': [('11:42 PM', 'Sunday', 301, 205), ('09:51 AM', 'Monday', 135, 210), ('12:20 PM', 'Monday', 646, 204), ('12:33 PM', 'Wednesday', 630, 204), ('03:17 AM', 'Thursday', 126, 219)], 'target_stay': ('05:46 AM', 'Thursday', None, '<next_place_id>')}, {'context_stay': [('09:51 AM', 'Monday', 135, 210), ('12:20 PM', 'Monday', 646, 204), ('12:33 PM', 'Wednesday', 630, 204), ('03:17 AM', 'Thursday', 126, 219), ('05:46 AM', 'Thursday', 74, 1)], 'target_stay': ('07:41 AM', 'Thursday', None, '<next_place_id>')}, {'context_stay': [('12:20 PM', 'Monday', 646, 204), ('12:33 PM', 'Wednesday', 630, 204), ('03:17 AM', 'Thursday', 126, 219), ('05:46 AM', 'Thursday', 74, 1), ('07:41 AM', 'Thursday', 110, 204)], 'target_stay': ('09:35 AM', 'Thursday', None, '<next_place_id>')}, {'context_stay': [('12:33 PM', 'Wednesday', 630, 204), ('03:17 AM', 'Thursday', 126, 219), ('05:46 AM', 'Thursday', 74, 1), ('07:41 AM', 'Thursday', 110, 204), ('09:35 AM', 'Thursday', 128, 210)], 'target_stay': ('11:44 PM', 'Thursday', None, '<next_place_id>')}, {'context_stay': [('03:17 AM', 'Thursday', 126, 219), ('05:46 AM', 'Thursday', 74, 1), ('07:41 AM', 'Thursday', 110, 204), ('09:35 AM', 'Thursday', 128, 210), ('11:44 PM', 'Thursday', 191, 217)], 'target_stay': ('07:51 AM', 'Friday', None, '<next_place_id>')}, {'context_stay': [('05:46 AM', 'Thursday', 74, 1), ('07:41 AM', 'Thursday', 110, 204), ('09:35 AM', 'Thursday', 128, 210), ('11:44 PM', 'Thursday', 191, 217), ('07:51 AM', 'Friday', 40, 213)], 'target_stay': ('12:10 PM', 'Friday', None, '<next_place_id>')}, {'context_stay': [('07:41 AM', 'Thursday', 110, 204), ('09:35 AM', 'Thursday', 128, 210), ('11:44 PM', 'Thursday', 191, 217), ('07:51 AM', 'Friday', 40, 213), ('12:10 PM', 'Friday', 798, 209)], 'target_stay': ('08:48 AM', 'Saturday', None, '<next_place_id>')}, {'context_stay': [('09:35 AM', 'Thursday', 128, 210), ('11:44 PM', 'Thursday', 191, 217), ('07:51 AM', 'Friday', 40, 213), ('12:10 PM', 'Friday', 798, 209), ('08:48 AM', 'Saturday', 176, 210)], 'target_stay': ('08:02 AM', 'Sunday', None, '<next_place_id>')}, {'context_stay': [('11:44 PM', 'Thursday', 191, 217), ('07:51 AM', 'Friday', 40, 213), ('12:10 PM', 'Friday', 798, 209), ('08:48 AM', 'Saturday', 176, 210), ('08:02 AM', 'Sunday', 61, 22)], 'target_stay': ('09:19 AM', 'Sunday', None, '<next_place_id>')}]\n",
      "------\n",
      "[('12:46 AM', 'Wednesday', 401, 220), ('09:13 AM', 'Thursday', 1005, 1), ('03:35 AM', 'Friday', 41, 210), ('04:49 AM', 'Friday', 123, 205), ('07:19 AM', 'Friday', 139, 221)]\n",
      "------\n",
      "{'context_stay': [('03:13 AM', 'Sunday', 106, 223), ('07:31 AM', 'Sunday', 280, 1), ('12:16 PM', 'Sunday', 645, 204), ('11:42 PM', 'Sunday', 301, 205), ('09:51 AM', 'Monday', 135, 210)], 'target_stay': ('12:20 PM', 'Monday', None, '<next_place_id>')}\n"
     ]
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:44:32.087805Z",
     "start_time": "2025-01-01T20:44:32.084812Z"
    }
   },
   "cell_type": "code",
   "source": "unique_values = tv_data['user_id'].unique()\n",
   "id": "5074ae1a02533d80",
   "outputs": [],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-02T03:11:18.681635Z",
     "start_time": "2025-01-02T03:11:18.672398Z"
    }
   },
   "cell_type": "code",
   "source": "## 测试 ",
   "id": "2792af62a0024a82",
   "outputs": [],
   "execution_count": 17
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:45:23.127729Z",
     "start_time": "2025-01-01T20:45:23.119731Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def create_qurey(historical_data, X):\n",
    "    U_value = f\"\"\"\n",
    "    Your task is to predict a user's next location based on his/her activity pattern.\n",
    "    You will be provided <context> which provide contextual information about where and when this user has been to recently.\n",
    "    Each stay takes on such form as (start_time, day_of_week, duration, place_id). The detailed explanation of each element is as follows:\n",
    "    start_time: the start time of the stay in 12h clock format.\n",
    "    day_of_week: indicating the day of the week.\n",
    "    duration: an integer indicating the duration (in minute) of each stay. Note that this will be None in the <target_stay> introduced later.\n",
    "    place_id: an integer representing the unique place ID, which indicates where the stay is.\n",
    "\n",
    "    Then you need to do next location prediction on <target_stay> which is the prediction target with unknown place ID denoted as <next_place_id> and unknown duration denoted as None, while temporal information is provided.      \n",
    "    \n",
    "    Please infer what the <next_place_id> is (i.e., the most likely place ID), considering the following aspects:\n",
    "    1. the activity pattern of this user that you leared from <history>, e.g., repeated visit to a certain place during certain time;\n",
    "    2. the context stays in <context>, which provide more recent activities of this user; \n",
    "    3. the temporal information (i.e., start_time and day_of_week) of target stay, which is important because people's activity varies during different times (e.g., nighttime versus daytime) and on different days (e.g., weekday versus weekend).\n",
    "\n",
    "    Please organize your answer in a JSON object containing following keys: \"prediction\" (place ID) and \"reason\" (a concise explanation that supports your prediction). Do not include line breaks in your output.\n",
    "\n",
    "    The data are as follows:\n",
    "    <context>: {X['context_stay']}\n",
    "    <target_stay>: {X['target_stay']}\n",
    "    \"\"\"\n",
    "    A_value =  f\"\"\"\n",
    "    Your task is to predict a user's next location based on his/her activity pattern.\n",
    "    You will be provided with <history> which is a list containing this user's historical stays, then <context> which provide contextual information about where and when this user has been to recently. Stays in both <history> and <context> are in chronological order.\n",
    "    Each stay takes on such form as (start_time, day_of_week, duration, place_id). The detailed explanation of each element is as follows:\n",
    "    start_time: the start time of the stay in 12h clock format.\n",
    "    day_of_week: indicating the day of the week.\n",
    "    duration: an integer indicating the duration (in minute) of each stay. Note that this will be None in the <target_stay> introduced later.\n",
    "    place_id: an integer representing the unique place ID, which indicates where the stay is.\n",
    "\n",
    "    Then you need to do next location prediction on <target_stay> which is the prediction target with unknown place ID denoted as <next_place_id> and unknown duration denoted as None, while temporal information is provided.      \n",
    "    \n",
    "    Please infer what the <next_place_id> is (i.e., the most likely place ID), considering the following aspects:\n",
    "    1. the activity pattern of this user that you leared from <history>, e.g., repeated visit to a certain place during certain time;\n",
    "    2. the context stays in <context>, which provide more recent activities of this user; \n",
    "    3. the temporal information (i.e., start_time and day_of_week) of target stay, which is important because people's activity varies during different times (e.g., nighttime versus daytime) and on different days (e.g., weekday versus weekend).\n",
    "\n",
    "    Please organize your answer in a JSON object containing following keys: \"prediction\" (place ID) and \"reason\" (a concise explanation that supports your prediction). Do not include line breaks in your output.\n",
    "\n",
    "    The data are as follows:\n",
    "    <history>: {historical_data}\n",
    "    <context>: {X['context_stay']}\n",
    "    <target_stay>: {X['target_stay']}\n",
    "    \"\"\"\n",
    "    return U_value, A_value\n",
    "\n",
    "\n",
    "def create_con(U_value,A_value):\n",
    "    conversations = [\n",
    "        {\n",
    "            \"from\": \"user\",\n",
    "            \"value\": U_value\n",
    "        },\n",
    "        {\n",
    "            \"from\": \"assistant\",\n",
    "            \"value\": A_value\n",
    "        }\n",
    "    ]\n",
    "    return conversations"
   ],
   "id": "1bb059f25d69af11",
   "outputs": [],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:45:31.784444Z",
     "start_time": "2025-01-01T20:45:31.702314Z"
    }
   },
   "cell_type": "code",
   "source": [
    "num_context_stay = 5  #决定历史轨迹k的数量\n",
    "\n",
    "template = []  #创建空的列表，用于储存更新后的数据\n",
    "\n",
    "idx = 0\n",
    "\n",
    "for i in unique_values[:20]:\n",
    "    user_train = get_user_data(tv_data, i, num_context_stay)\n",
    "    historical_data, predict_X, predict_y = organise_data(user_train, test_file, i, 5)\n",
    "    for j in range(len(predict_X)):\n",
    "        X = predict_X[j]\n",
    "        U_value, A_value = create_qurey(historical_data, X)\n",
    "        conversations = create_con(U_value, A_value)\n",
    "        template.append({\n",
    "            \"id\": f\"identity_{idx}\",\n",
    "            \"conversations\": conversations\n",
    "        }) \n",
    "        idx +=1\n",
    "        "
   ],
   "id": "ab2c6d06f98cda4d",
   "outputs": [],
   "execution_count": 17
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:45:33.775145Z",
     "start_time": "2025-01-01T20:45:33.766146Z"
    }
   },
   "cell_type": "code",
   "source": "print(json.dumps(template[2], ensure_ascii=False, indent=2))",
   "id": "2f9f08776141fe44",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"id\": \"identity_2\",\n",
      "  \"conversations\": [\n",
      "    {\n",
      "      \"from\": \"user\",\n",
      "      \"value\": \"\\n    Your task is to predict a user's next location based on his/her activity pattern.\\n    You will be provided <context> which provide contextual information about where and when this user has been to recently.\\n    Each stay takes on such form as (start_time, day_of_week, duration, place_id). The detailed explanation of each element is as follows:\\n    start_time: the start time of the stay in 12h clock format.\\n    day_of_week: indicating the day of the week.\\n    duration: an integer indicating the duration (in minute) of each stay. Note that this will be None in the <target_stay> introduced later.\\n    place_id: an integer representing the unique place ID, which indicates where the stay is.\\n\\n    Then you need to do next location prediction on <target_stay> which is the prediction target with unknown place ID denoted as <next_place_id> and unknown duration denoted as None, while temporal information is provided.      \\n    \\n    Please infer what the <next_place_id> is (i.e., the most likely place ID), considering the following aspects:\\n    1. the activity pattern of this user that you leared from <history>, e.g., repeated visit to a certain place during certain time;\\n    2. the context stays in <context>, which provide more recent activities of this user; \\n    3. the temporal information (i.e., start_time and day_of_week) of target stay, which is important because people's activity varies during different times (e.g., nighttime versus daytime) and on different days (e.g., weekday versus weekend).\\n\\n    Please organize your answer in a JSON object containing following keys: \\\"prediction\\\" (place ID) and \\\"reason\\\" (a concise explanation that supports your prediction). Do not include line breaks in your output.\\n\\n    The data are as follows:\\n    <context>: [('08:07 AM', 'Thursday', 146, 1), ('10:35 AM', 'Thursday', 193, 17), ('01:54 PM', 'Thursday', 556, 10), ('12:36 AM', 'Friday', 546, 42), ('11:27 AM', 'Friday', 45, 1)]\\n    <target_stay>: ('01:37 PM', 'Friday', None, '<next_place_id>')\\n    \"\n",
      "    },\n",
      "    {\n",
      "      \"from\": \"assistant\",\n",
      "      \"value\": \"\\n    Your task is to predict a user's next location based on his/her activity pattern.\\n    You will be provided with <history> which is a list containing this user's historical stays, then <context> which provide contextual information about where and when this user has been to recently. Stays in both <history> and <context> are in chronological order.\\n    Each stay takes on such form as (start_time, day_of_week, duration, place_id). The detailed explanation of each element is as follows:\\n    start_time: the start time of the stay in 12h clock format.\\n    day_of_week: indicating the day of the week.\\n    duration: an integer indicating the duration (in minute) of each stay. Note that this will be None in the <target_stay> introduced later.\\n    place_id: an integer representing the unique place ID, which indicates where the stay is.\\n\\n    Then you need to do next location prediction on <target_stay> which is the prediction target with unknown place ID denoted as <next_place_id> and unknown duration denoted as None, while temporal information is provided.      \\n    \\n    Please infer what the <next_place_id> is (i.e., the most likely place ID), considering the following aspects:\\n    1. the activity pattern of this user that you leared from <history>, e.g., repeated visit to a certain place during certain time;\\n    2. the context stays in <context>, which provide more recent activities of this user; \\n    3. the temporal information (i.e., start_time and day_of_week) of target stay, which is important because people's activity varies during different times (e.g., nighttime versus daytime) and on different days (e.g., weekday versus weekend).\\n\\n    Please organize your answer in a JSON object containing following keys: \\\"prediction\\\" (place ID) and \\\"reason\\\" (a concise explanation that supports your prediction). Do not include line breaks in your output.\\n\\n    The data are as follows:\\n    <history>: [('11:37 AM', 'Wednesday', 305, 17), ('04:45 PM', 'Wednesday', 551, 18), ('02:16 AM', 'Thursday', 95, 17), ('04:25 AM', 'Thursday', 354, 10), ('10:28 AM', 'Thursday', 913, 17)]\\n    <context>: [('08:07 AM', 'Thursday', 146, 1), ('10:35 AM', 'Thursday', 193, 17), ('01:54 PM', 'Thursday', 556, 10), ('12:36 AM', 'Friday', 546, 42), ('11:27 AM', 'Friday', 45, 1)]\\n    <target_stay>: ('01:37 PM', 'Friday', None, '<next_place_id>')\\n    \"\n",
      "    }\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:45:40.099705Z",
     "start_time": "2025-01-01T20:45:40.045707Z"
    }
   },
   "cell_type": "code",
   "source": [
    "output_file_path = \"data/path_data.json\"\n",
    "with open(output_file_path, 'w', encoding='utf-8') as f:\n",
    "    json.dump(template, f, ensure_ascii=False, indent=2)\n",
    "    \n",
    "print(f\"处理好的数据已写入到本地文件: {output_file_path}\")"
   ],
   "id": "40579ae858cbd3d6",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "处理好的数据已写入到本地文件: data/path_data.json\n"
     ]
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-30T12:39:50.149857Z",
     "start_time": "2024-12-30T12:39:50.131564Z"
    }
   },
   "cell_type": "code",
   "source": "\n",
   "id": "7e53dee68df460e0",
   "outputs": [],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-02T03:18:17.167762Z",
     "start_time": "2025-01-02T03:18:17.155136Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "544d81547fc388cf",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "identity_101\n"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-01T20:33:58.213105Z",
     "start_time": "2025-01-01T20:33:58.209105Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "b78d5527ada70de2",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "execution_count": 2
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
